﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="/js/header.js"></script>
</head>
<body style="background-color: white;">
    <section class="container-fluid" style="background-color: white;">
        <form class="form-horizontal m15_t" id="form">
            <div class="tab-content">
                <input type="hidden" id="pid" name="pid" value="0">
                <div class="tab-pane fade in active" id="home">
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>权限名称：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="pName" maxlength="40" autocomplete="off" placeholder="长度必须介于 3 和 40 之间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>权限代码：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="pCode" maxlength="40" autocomplete="off" placeholder="长度必须介于 3 和 40 之间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>排序：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="sortNo" maxlength="2" autocomplete="off" placeholder="排序只能为整数">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label">状态：</label>
                        <div class="wd250 m15_l">
                            <label class="m10_r">
                                <input type="radio" name="hide" value="1"> 启用
                            </label>
                            <label>
                                <input type="radio" name="hide" value="2"> 禁用
                            </label>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </section>
</body>
</html>
<script type="text/javascript">

    var validator = null;

    function init() {

        var cover = FlashPay.UI.Mask({
            obj: $("body"),
            opacity: 0.5
        });

        FlashPay.Util.Ajax({
            type: "POST",
            url: "/Permission/GetAddOrEdit/" + FlashPay.Util.GetQueryString("id"),
            data: null,
            success: function (response) {

                if (response.success) {
                    FlashPay.Util.SetInputVal("pid", response.data.pid);
                    FlashPay.Util.SetInputVal("pName", response.data.pName)
                    FlashPay.Util.SetInputVal("pCode", response.data.pCode)
                    FlashPay.Util.SetInputVal("sortNo", response.data.sortNo)
                    $("input[name=hide][value='" + response.data.hide + "']").attr("checked", true);
                    cover.Remove();
                } else {
                    FlashPay.UI.Tip_short_warning(response.errorMessage);
                }
            },
            error: function (e) {

                cover.Remove();
                FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试");
            }
        });
    }

    $(function () {

        validator = FlashPay.Util.Validator({
            formObj: $("#form"),
            rules: {
                pName: {
                    required: true,
                    rangelength: [3, 40]
                },
                pCode: {
                    required: true,
                    rangelength: [3, 40]
                },
                sortNo: {
                    required: true,
                    IsPositiveInteger: true
                }
            },
            messages: {
                pName: {
                    required: "长度必须介于 3 和 40 之间",
                    rangelength: "长度必须介于 3 和 40 之间",
                },
                pCode: {
                    required: "长度必须介于 3 和 40 之间",
                    rangelength: "长度必须介于 3 和 40 之间",
                },
                sortNo: {
                    required: "排序只能为整数",
                    IsPositiveInteger: "排序只能为整数"
                }
            },
        });

        init();
    })

    function save() {

        if (!validator.form()) {
            return false;
        }

        var permission = {};
        permission.pid = $("input[name='pid']").val();
        permission.pName = $("input[name='pName']").val();
        permission.pCode = $("input[name='pCode']").val();
        permission.sortNo = $("input[name='sortNo']").val();
        
        var hide = $(":radio[name='hide']:checked").val();
        if (hide == undefined) {
            FlashPay.UI.Tip_short_warning("请选择状态！");
            return;
        }
        permission.hide = hide;

        FlashPay.Util.Ajax({
            url: '/permission/SaveOrEdit',
            type: 'POST',
            data: { permission: permission },
            success: function (response) {
                if (response.success) {
                    FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                    FlashPay.UI.DialogOpener().doSearch();
                    FlashPay.UI.CloseDialog();
                } else {
                    FlashPay.UI.Tip_short_warning("操作失败！" + response.errorMessage);
                }
            },
            error: function (json) {
                FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试!");
            }
        });
    }
</script>